import QtQuick 2.15
import QtQuick.Controls 2.15
import QtQuick.Shapes 1.15

MainView {
    id: root
    width: 800
    height: 391

    property int selectedSubView: 1             //C 整体显示内容（可以看成是LeftView和RightVie的组合）。
    property int selectedLeftView: 0
    property int selectedRightView: 1

    Component.onCompleted: {
        //mainLoader.visible=false;
    }
    onVisibleChanged: {
        if(visible)
        {
            valuePanel.startTimer()
        }
        else
        {
            valuePanel.stopTimer()
        }
    }
    LightBar {      //哦哦，一行Button风格的显示，HH  HL  OK  LO  LL.
        id: lightBar
        x: 0
        y: 0
        width: 532
        height: 36
    }
    Item {
        id: leftItem
        x: 0
        y: 40
        width: 532
        height: 349
        property int currentViewIndex: 0

        ValuePanel {
            id: valuePanel
            enabled: root.selectedLeftView === 0
            visible: opacity > 0.01
            anchors.fill: parent

            selectedView: root.selectedLeftView
            index: 0
        }

        GraphPanel {
            id: graphPanel
            enabled: root.selectedLeftView === 1
            visible: opacity > 0.01
            anchors.fill: parent

            selectedView: root.selectedLeftView
            index: 1
        }
    }
    /*ValuePanel
    {
        id:valuePanel
        x: 0
        y: 40
    }*/
    Button
    {
        id:btnSwitchMode
        x: 584
        y: 6
        width: 180
        height: 50
        background: Rectangle{
            border.width: btnSwitchMode.down?1: 0
            color: btnSwitchMode.down?"#FF614B": "#C070B0"
            border.color: "#F0D070"
                }

        text: qsTr("操作")
        font.pixelSize: 25
        palette.buttonText: "white"
        //Connections {   //C 为什么使用Connections{}？
        //    target: btnSwitchMode
            onClicked: {
                //selectedSubView切换顺序1(操作)-0(比较)-2(计数)-3(图形)-1(操作)
                //selectedLeftView 0 值界面  1 图形界面
                switch(root.selectedSubView)
                {
                    case 0:
                        root.selectedSubView = 2;       //C  哦哦，像是selectedLeftView和selectedRightView的组合名称。
                        root.selectedLeftView = 0;      //C 决定左侧实现什么。
                        root.selectedRightView = 2;     //C 决定右侧显示什么。
                        btnSwitchMode.text =qsTr("计数");
                        break;
                    case 1:
                        root.selectedSubView = 0;
                        root.selectedLeftView = 0;
                        root.selectedRightView = 0;
                        btnSwitchMode.text =qsTr("比较");
                        break;
                    case 2:
                        root.selectedSubView = 3;
                        root.selectedLeftView = 1;
                        root.selectedRightView = 3;
                        btnSwitchMode.text =qsTr("图形");
                        break;
                    case 3:
                        graphRightPanel.stopGraph()
                        root.selectedSubView = 1;
                        root.selectedLeftView = 0;
                        root.selectedRightView = 1;
                        btnSwitchMode.text =qsTr("操作");
                        break;
                    case 4:
                        graphRightPanel.stopGraph()
                        root.selectedSubView = 0;
                        root.selectedLeftView = 0;
                        root.selectedRightView = 0;
                        btnSwitchMode.text =qsTr("比较");
                        break;
                    //C 没有"角度"。
                }
            }
        //}
    }
    Item {
        /* 通过控制多个控件的显示，
        */
        id: subItem0
        height: 325
        width: 253
        //anchors.left: 542
        //anchors.right: parent.right
        //anchors.top: 61
        property int currentViewIndex: 4
        x: 542
        y: 61
        ComparePanel {
            id: comparePanel
            enabled: root.selectedRightView === 0
            visible: opacity > 0.01
            anchors.fill: parent

            selectedView: root.selectedRightView    //C 哦哦，向内层传递外层的参数值。
            index: 0
        }
        OperationPanel {
            id: operationPanel
            enabled: root.selectedRightView === 1
            visible: opacity > 0.01
            anchors.fill: parent

            selectedView: root.selectedRightView
            index: 1
        }
        CountPanel {
            id: countPanel
            enabled: root.selectedRightView === 2
            visible: opacity > 0.01
            anchors.fill: parent

            selectedView: root.selectedRightView
            index: 2
        }


        GraphRightPanel {
            id: graphRightPanel
            enabled: root.selectedRightView === 3
            visible: opacity > 0.01
            anchors.fill: parent

            selectedView: root.selectedRightView
            index: 3
        }
        Angle{
            id: anglePanel
            enabled: root.selectedRightView === 4
            visible: opacity > 0.01
            anchors.fill: parent

            selectedView: root.selectedRightView
            index: 4
        }
    }

    Dialog {
        anchors.centerIn: parent
        id: saveWeightOKDialog
        //title: "提示"
        standardButtons: Dialog.Ok
        title:qsTr("保存成功！")
        modal: true
        closePolicy: "CloseOnEscape"
        onAccepted: saveWeightOKDialog.close()
        z:100
        //onRejected: console.log("Cancel clicked")
    }

    MyBuzyIndicator{
        anchors.centerIn: parent
        id: angleLoader
        visible:false
        z:101
    }
}
